<style>
#zxzpSpgg .table tr td,
#zxzpSpgg .table tr th {
    text-align: center;
    height: 42px;
    line-height: 42px;
    padding: 0;
}

#zxzpSpgg .top-container {
    padding: 10px;
    background-color: #f5f5f5;
}

#zxzpSpgg .sn-col {
    display: inline-block;
}

#zxzpSpgg .search-text {
    width: 650px !important;
    margin-left: 10px;
}
#zxzpSpgg .table tr td, #zxzpZpgg .table tr th {
    text-align: center;
    height: 42px;
    line-height: 42px;
    padding: 0;
}

#zxzpSpgg .zxzpZgpp-info-title {
    width: 130px;
    text-align: right !important;
    padding-right: 9px !important;
}
#zxzpSpgg .zxzp-btn-row{
    text-align: center;
}
#zxzpSpgg .zxzp-btn-row .btn{
    height: auto;
    font-size: 14px;
    margin: 0 10px;
}
</style>
<div id="zxzpSpgg" ms-controller="zxzpSpgg">
    <div class="zxzpSpgg super-level" id="zxzpSpgg1">
        <div class="top-container">
            <div class="">
                <div class="sn-col">
                    <div class="input-group search">
                        <input type="text" class="form-control search-text" placeholder="" ms-redux="searchText">
                        <span class="input-group-btn">
                            <button class="btn btn-info" type="button" ms-click="searhNoticeList">搜索</button>
                        </span>
                    </div>
                </div>
            </div>
        </div>
        <div class="list" id="zxzpSpggList">
            <div class="sn-tab">
                <div class="sn-tab-nav">
                    <div class="sn-tab-nav-item active">待审批({{noticeList.process.total}})</div>
                    <div class="sn-tab-nav-item">已审批({{noticeList.publish.total}})</div>
                </div>
                <div class="sn-tab-body">
                    <div class="sn-tab-body-item" style="display: block;">
                        <table class="table table-bordered">
                            <tr>
                                <th>招聘公告</th>
                                <th>职位数</th>
                                <th>人数</th>
                                <th>发布时间</th>
                                <th>截止日期</th>
                                <th>操作</th>
                            </tr>
                            <tr ms-repeat="noticeList.process.data">
                                <td>
                                    <a ms-click="approveNotice(el,true)">{{el.JobName}}</a>
                                </td>
                                <td>{{el.JobPosCount}}</td>
                                <td>{{el.TotalPeople}}</td>
                                <td>{{el.TimeCreated}}</td>
                                <td>{{el.TimeEnd}}</td>
                                <td>
                                    <button class="btn-sm btn-info" ms-click="approveNotice(el,true)">审批</button>
                                </td>
                            </tr>
                        </table>
                        <div id="processListPager" class="dp" style="text-align: center;"></div>
                    </div>
                    <div class="sn-tab-body-item">
                        <table class="table table-bordered">
                            <tr>
                                <th>招聘公告</th>
                                <th>职位数</th>
                                <th>人数</th>
                                <th>发布时间</th>
                                <th>截止日期</th>
                            </tr>
                            <tr ms-repeat="noticeList.publish.data">
                                <td>
                                    <a ms-click="approveNotice(el,false)">{{el.JobName}}</a>
                                </td>
                                <td>{{el.JobPosCount}}</td>
                                <td>{{el.TotalPeople}}</td>
                                <td>{{el.TimeCreated}}</td>
                                <td>{{el.TimeEnd}}</td>
                            </tr>
                        </table>
                        <div id="publishListPager" class="dp" style="text-align: center;"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="viewJobSpgg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" onclick="hideViewJobSpgg()">
        <div class="modal-dialog" role="document" style="width: 822px;">
            <div class="modal-content" style="border-radius: 0;">
                <div class="modal-header" style="border-bottom-color:#237dc2;margin: 0 15px; text-indent: 15px;">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" onclick="hideViewJobSpgg()" id="closeViewJobSpgg">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel" style="color: #237dc2;font-size: 16px;">{{notice.viewJob.JobName}}</h4>
                </div>
                <div class="modal-body">
                    <div>
                        <div style="margin-top:25px;padding: 0 10px; ">
                            <div style="width: 35%;display: inline-block;font-size:14px;">
                                <span>招聘信息编号：</span>
                                <span>{{notice.viewJob.JobCode}}</span>
                            </div>
                            <div style="width: 35%;display: inline-block;font-size:14px;">
                                <span>招聘计划年度：</span>
                                <span>{{notice.viewJob.Year}}</span>
                            </div>
                            <div style="width: 24%;display: inline-block;font-size:14px;">
                                <span>招聘单位：</span>
                                <span>{{zxzpSpgg.userInfo.DepartmentName}}</span>
                            </div>
                        </div>
                        <div style="margin-top: 5px;">
                            <table class="table table-bordered">
                                <tr>
                                    <td class="zxzpZgpp-info-title">招聘目的及说明</td>
                                    <td>{{notice.viewJob.Caption}}</td>
                                </tr>
                                <tr>
                                    <td class="zxzpZgpp-info-title">录用形式</td>
                                    <td>{{notice.viewJob.DeployMode}}</td>
                                </tr>
                                <tr>
                                    <td class="zxzpZgpp-info-title">报名截止日期</td>
                                    <td>{{notice.viewJob.TimeEnd}}</td>
                                </tr>
                                <tr>
                                    <td class="zxzpZgpp-info-title">联系方式</td>
                                    <td>{{notice.viewJob.Linkman}}</td>
                                </tr>
                                <tr>
                                    <td class="zxzpZgpp-info-title">招聘面向单位</td>
                                    <td id="zpmxdwSpgg"></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div style="margin-top: 15px;">
                        <p style="font-size: 16px;padding-left: 10px;color: #f10202;">岗位信息</p>
                        <table class="table table-bordered">
                            <tr>
                                <th>序号</th>
                                <th>岗位名称</th>
                                <th>工作单位</th>
                                <th>工作地点</th>
                                <th>招聘人数</th>
                            </tr>
                            <tr ms-repeat="notice.positionList">
                                <td>{{$index}}</td>
                                <td>{{el.PositionName}}</td>
                                <td>工作单位</td>
                                <td>{{el.GZDDch}}</td>
                                <td>{{el.Number}}</td>
                            </tr>
                        </table>
                        <div class="zxzp-btn-row">
                            <div class="btn btn-sm btn-info" onclick="auditJob(11)">审批通过并发布</div>
                            <div class="btn btn-sm btn-info" data-toggle="modal" data-target="#decline" onclick="clearOpinion()">审批不通过</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="decline" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document"  style="width: 400px;margin-top: 200px">
            <div class="modal-content" style="border-radius: 0;">
                <div class="modal-header" style="border-bottom-color:#237dc2;">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" style="color: #237dc2;font-size: 14px;">审批不通过的理由</h4>
                </div>
                <div class="modal-body">
                        <textarea name="" id="" cols="30" rows="10" ms-duplex="opinion" style="width: 100%;resize:none;">
                            
                        </textarea>
                        <div class="zxzp-btn-row">
                            <div class="btn btn-sm btn-danger" onclick="auditJob(12)">审批不通过</div>
                            <div id="cancelAuditJob" class="btn btn-sm btn-cancel" data-dismiss="modal" style="background: #ccc">取消</div>
                        </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
var zxzpSpgg = avalon.define({
    $id: "zxzpSpgg",
    userInfo:{},
    jobId: '',
    opinion:'',
    notice: {
        viewJob: {},
        positionList: []
    },
    noticeList: {
        process: {
            data: [],
            total: 0
        },
        publish: {
            data: [],
            total: 0
        }
    }
});
setTimeout(initZxzpSpgg, 0);

function initZxzpSpgg() {
    if(window.userInfo){
        setUserInfo();
    }else{
        $.get(getUserInfo,function(data){
            if(data.result.Status == true){
                window.userInfo = data.Message;
                setUserInfo();
            }            
        },'json')
    }
    $("#zxzpSpgg .sn-tab-nav-item").click(function(event) {
        var index = $(this).index();
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
        $(this).parent().next().find(".sn-tab-body-item").hide().eq(index).show();
    });
    getDefaultSpgg();
}
function setUserInfo() {
    zxzpSpgg.userInfo = window.userInfo;
}
function getDefaultSpgg() {
    //审批中
    getJobListByStatusSpgg(true, 10, 'process');
    //发布中
    getJobListByStatusSpgg(true, 11, 'publish');
}

function getJobListByStatusSpgg(isPage, status, tabName, pageSize, pageIndex) {
    var isPage = isPage || false;
    var pageSize = pageSize || 5;
    var pageIndex = pageIndex || 1;
    $.post(GetJobZXListByStatus, {
        status: status,
        pageSize: pageSize,
        pageIndex: pageIndex
    }, function(result) {
        if (result.Status == true) {
            zxzpSpgg.noticeList[tabName].data = result.Message.List;
            zxzpSpgg.noticeList[tabName].total = result.Message.RecordCount;
            //创建分页
            if (isPage) {
                createPageSpgg(status, tabName, pageSize, result.Message.RecordCount);
            }
        }
    }, 'json');
}

function createPageSpgg(status, tabName, pageSize, total) {
    $('#' + tabName + 'ListPagerSpgg').extendPagination({
        totalCount: total,
        showCount: pageSize,
        limit: 5,
        callback: getJobListByStatusSpgg[tabName]
    });
}
function clearOpinion(){
    zxzpSpgg.opinion = '';
}
function hideViewJobSpgg(e) {
    var e = e || event;
    if (e.target.id == 'viewJobSpgg' || e.target.id == "closeViewJobSpgg") {
        $("#viewJobSpgg").removeClass('in');
        setTimeout(function() {
            $("#viewJobSpgg").hide();
        }, 500);
        $("#viewJobModalSpgg").remove();
    }
}

function approveNotice(el,isShow) {
    zxzpSpgg.notice.positionList = [];
    zxzpSpgg.jobId = el.Id;
    var data = {
        jobId: el.Id
    };
    $.post(GetJobById, data, function(result) {
        if (result.Status == true) {
            zxzpSpgg.notice.viewJob = result.Message;
            showViewJobSpgg(isShow);
        } else {
            alert("网络错误，请稍后再试");
        }
    }, 'json');
    $.post(GetPositionZXByJobId, data, function(result) {
        if (result.Status == true) {
            zxzpSpgg.notice.positionList = result.Message;            
        } else {
            alert("网络错误，请稍后再试");
        }
    }, 'json');
}

function showViewJobSpgg(isShow) {
    if(isShow){
        $("#zxzpSpgg .zxzp-btn-row").show();
    }else{
        $("#zxzpSpgg .zxzp-btn-row").hide();
    }
    $("#viewJobSpgg").show().addClass('in');
    $("body").append('<div class="modal-backdrop fade in" id="viewJobModalSpgg"></div>');
}
function auditJob(status){
    if(!status){
        alert('参数错误');
        return ;
    }
    var data = {
        jobId:zxzpSpgg.jobId,
        status:status,
        opinion:zxzpSpgg.opinion
    }
    $.post(AuditJob,data,function(result){
        if(result.Status == true){
            alert("操作完成");
            $("#closeViewJobSpgg").click();
            $("#cancelAuditJob").click();
            getDefaultSpgg();
        }else{
            alert("网络错误，请稍后再试");
        }
    },'json');
}
</script>
